﻿<!-- #include file="../ding.asp" -->
<!-- #include file="../mymin.asp" -->
<%Call Head()%>
<card title="文件管理"><p>
<%
IF KEY<>0 then
	Call Error("你的权限不足！")
end if

w systemMsgRoot

dim UploadDir
UploadDir="../../upload"
Const MaxPerPage=10

dim strFileName,totalPut,CurrentPage,TotalPages,TruePath,fso,theFolder,theFile,whichfile,thisfile,FileCount,TotleSize
Dim path,theSubfolder,fileArrayToString,fileArraySeparate,fileArray,fileArrayCount
strFileName="?"

if request("page")<>"" then
	currentPage=cint(request("page"))
else
	currentPage=1
end if

path=request("path")
if path <>"" then UploadDir = path

TruePath=Server.MapPath(UploadDir)

fileArrayToString = "FirstIndexIsEmpty"
fileArraySeparate = Chr(10)&Chr(10)

If not ifObjInstalled("Scripting.FileSystemObject") Then
	Response.Write "你的服务器不支持 FSO(Scripting.FileSystemObject)! 不能使用本功能"
Else
	set fso=CreateObject("Scripting.FileSystemObject")

	if fso.FolderExists(TruePath)then
		FileCount=0
		TotleSize=0
		Set theFolder=fso.GetFolder(TruePath)
		For Each theSubfolder in theFolder.subfolders
			fileArrayToString =  fileArrayToString& fileArraySeparate & "<a href=""fileman.asp?sid="&sid&"&amp;path="&UploadDir&"/"&theSubfolder.name&""">"&theSubfolder.name&"/..</a>"
		Next

		For Each theFile In theFolder.Files
			FileCount=FileCount+1
			TotleSize=TotleSize+theFile.Size
			fileArrayToString =  fileArrayToString& fileArraySeparate & "<a href="""&UploadDir&"/"&theFile.name&""">"&theFile.name&"</a>"&_
				"[<a href=""filedel.asp?path="&(UploadDir &"/"& theFile.Name)&"&amp;pathname="&theFile.Name&"&amp;TP="&TP&"&amp;sid="&sid&""">删</a>]"
		next
		fileArray = Split(fileArrayToString, fileArraySeparate)
		fileArrayCount=UBound(fileArray)
		
		totalPut=fileArrayCount
		if currentpage<1 then
			currentpage=1
		end if
		if (currentpage-1)*MaxPerPage>totalput then
			if (totalPut mod MaxPerPage)=0 then
				currentpage= totalPut \ MaxPerPage
			else
				currentpage= totalPut \ MaxPerPage + 1
			end if

		end if
		if currentPage=1 then
			showFile
			showpage2 strFileName,totalput,MaxPerPage
		else
			if (currentPage-1)*MaxPerPage<totalPut then
				showFile
				showpage2 strFileName,totalput,MaxPerPage
			else
				currentPage=1
				showFile
				showpage2 strFileName,totalput,MaxPerPage
			end if
		end if
		response.write "<br/>当前目录共有" & FileCount & "个文件，占用" & TotleSize\1024 & " K"
	else
		response.write "找不到文件夹！可能是配置有误！"
	end if
end if

Sub showFile()
	Dim index
	For i=1 To MaxPerPage
		index = i +(CurrentPage-1)*MaxPerPage
		if index > fileArrayCount then exit sub
		Response.Write fileArray(index) & "<br/>"
	Next
End Sub

sub showpage2(sfilename,totalnumber,maxperpage)
	dim n, i,strTemp
	if totalnumber mod maxperpage=0 then
		n= totalnumber \ maxperpage
	else
		n= totalnumber \ maxperpage+1
	end if

	if n-currentpage<1 then
	else
		strTemp=strTemp & "<a href='fileman.asp?page=" & (CurrentPage+1) & "&amp;TP="&TP&"&amp;sid="&sid&"'>下一页</a>&nbsp;"
	end if

	if CurrentPage<2 then
	else
		strTemp=strTemp & "<a href='fileman.asp?page=" & (CurrentPage-1) & "&amp;TP="&TP&"&amp;sid="&sid&"'>上一页</a>&nbsp;"
	end if

	strTemp=strTemp & "<br/>(" & CurrentPage & "/" & n & ") "
	strTemp=strTemp & "共" & totalnumber & "个"

	if n>1 then
		strTemp=strTemp & "<input name=""page"" format=""*N"" value=""2"" type=""text"" maxlength=""5"" emptyok=""true"" size=""2""/><a href=""fileman.asp?page=$(page)&amp;TP="&TP&"&amp;sid="&sid&""">页</a>"
	end if
	response.write strTemp
end sub
%>
<br/><a href="Files.asp?sid=<%=sid%>">[文件管理]</a>
<br/><a href="index.asp?sid=<%=sid%>">[站长工具]</a>
<%Call Last%>